package com.lwq.view;

import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.lwq.controller.FileController;
import com.lwq.controller.ToolsController;
import com.lwq.util.Constance;

public class MenuView extends MenuBar{
	
	private Menu mFileMenu = null;
	private Menu mFileNewMenu = null;
	private Menu mEditMenu = null;
	private Menu mBuildMenu = null;
	private Menu mDesignMenu = null;
	private Menu mToolMenu = null;
	private Menu mProjectMenu = null;
	private Menu mProjectNewMenu = null;
	
	private MenuItem mOpenFileMenuItem = null;
	private MenuItem mImportFileMenuItem = null;
	private MenuItem mSaveFileMenuItem = null;
	private MenuItem mSaveAsFileMenuItem = null;
	
	private MenuItem mFileNewCocosMenuItem = null;
	private MenuItem mFileNewSceneMenuItem = null;
	private MenuItem mFileNewLayerMenuItem = null;
	private MenuItem mFileNewSpriteMenuItem = null;
	private MenuItem mFileNewActionMenuItem = null;
	
	private MenuItem mProNewDiretorMenuItem = null;
	private MenuItem mProNewSceneMenuItem = null;
	private MenuItem mProNewLayerMenuItem = null;
	private MenuItem mProNewSpriteMenuItem = null;
	private MenuItem mProNewActionMenuItem = null;
	
	private MenuItem mProBuildProjectMenuItem = null;
	private MenuItem mEditRefreshMenuItem = null;
	
	private MenuItem mToolsEditModelMenuItem = null;
	private Menu mToolsScreenMenu = null;
	private MenuItem mToolsScreen800X480ItemMenu = null;
	private MenuItem mToolsScreen480X800ItemMenu = null;
	
	public MenuView(){
		init();
		setEvent();
	}
	
	private void init(){
		mFileMenu = new Menu("File");
		mFileMenu.setEnabled(true);
		mEditMenu = new Menu("Edit");
		mEditMenu.setEnabled(true);
		mProjectMenu = new Menu("Project");
		mProjectMenu.setEnabled(true);
		mDesignMenu = new Menu("Design");
		mDesignMenu.setEnabled(true);
		mToolMenu = new Menu("Tools");
		mToolMenu.setEnabled(true);
		mBuildMenu = new Menu("Build");
		mBuildMenu.setEnabled(true);
		
		//------------menu---------------
		
		super.add((Menu)mFileMenu);
		super.add((Menu)mProjectMenu);
		super.add((Menu)mBuildMenu);
		super.add((Menu)mEditMenu);
		super.add((Menu)mDesignMenu);
		super.add((Menu)mToolMenu);
		
		
		//file
		mFileNewCocosMenuItem = new MenuItem("Cocos");
		mFileNewSceneMenuItem = new MenuItem("Scene");
		mFileNewLayerMenuItem = new MenuItem("Layer");
		mFileNewSpriteMenuItem = new MenuItem("Sprite");
		mFileNewActionMenuItem = new MenuItem("Action");
		mFileNewMenu = new Menu("New");
		mFileNewMenu.add(mFileNewCocosMenuItem);
		mFileNewMenu.add(mFileNewSceneMenuItem);
		mFileNewMenu.add(mFileNewLayerMenuItem);
		mFileNewMenu.add(mFileNewSpriteMenuItem);
		mFileNewMenu.add(mFileNewActionMenuItem);
		mFileMenu.add(mFileNewMenu);
		
		mOpenFileMenuItem = new MenuItem("Open");
		mImportFileMenuItem = new MenuItem("Import");
		mSaveFileMenuItem = new MenuItem("Save"); 
		mSaveAsFileMenuItem = new MenuItem("Save As"); 
		mOpenFileMenuItem.setEnabled(true);
		mImportFileMenuItem.setEnabled(true);
		mFileMenu.add(mOpenFileMenuItem);
		mFileMenu.add(mSaveFileMenuItem);
		mFileMenu.add(mSaveAsFileMenuItem);
		mFileMenu.add(mImportFileMenuItem);
		
		//project
		mProjectNewMenu = new Menu("Add");
		mProNewDiretorMenuItem = new MenuItem("Diretor");
		mProNewSceneMenuItem = new MenuItem("Scene");
		mProNewLayerMenuItem = new MenuItem("Layer");
		mProNewSpriteMenuItem = new MenuItem("Sprite");
		mProNewActionMenuItem = new MenuItem("Action");
		
		mProjectNewMenu.add(mProNewDiretorMenuItem);
		mProjectNewMenu.add(mProNewSceneMenuItem);
		mProjectNewMenu.add(mProNewLayerMenuItem);
		mProjectNewMenu.add(mProNewSpriteMenuItem);
		mProjectNewMenu.add(mProNewActionMenuItem);
		mProjectMenu.add(mProjectNewMenu);
		
		//Build
		mProBuildProjectMenuItem = new MenuItem("Bulid Project");
		mBuildMenu.add(mProBuildProjectMenuItem);
		
		//Edit
		mEditRefreshMenuItem = new MenuItem("Refresh");
		mEditMenu.add(mEditRefreshMenuItem);
		
		//Tools
		mToolsEditModelMenuItem = new MenuItem("EditModel");
		mToolMenu.add(mToolsEditModelMenuItem);
		
		mToolsScreenMenu = new Menu("Screen");
		mToolMenu.add(mToolsScreenMenu);
		
		mToolsScreen800X480ItemMenu = new MenuItem("800X480");
		mToolsScreenMenu.add(mToolsScreen800X480ItemMenu);
		
		mToolsScreen480X800ItemMenu = new MenuItem("480X800");
		mToolsScreenMenu.add(mToolsScreen480X800ItemMenu);
		
		
	}
	
	private void setEvent(){
		
		//new cocos project
		mFileNewCocosMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.newCocosCommand();
			}
		});
		
		//new Layout
		mFileNewLayerMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.newLayoutCommand();
			}
		});
		
		//new Sprite
		mFileNewSpriteMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.newSpriteCommand();
			}
		});
		
		//new Sence
		mFileNewSceneMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.newSenceCommand();
			}
		});
		
		mSaveFileMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.saveFileCommand();
			}
		});
		mOpenFileMenuItem.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent e)
			{
				FileController.openProjectCommand();
			}
		});
		mToolsEditModelMenuItem.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ToolsController.newEditModel();
			}
		});
		
		mToolsScreen800X480ItemMenu.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				CenterEditorView.getInstance().setScreenSize(800, 480);
			}
		});
		
		mToolsScreen480X800ItemMenu.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				CenterEditorView.getInstance().setScreenSize(480,800);
			}
		});
		
	}
}
